#include <minishell_core.h>

#include <stdio.h>
//一级函数
static int do_get_fpga_info(void *ptr, int argc, char **argv);
static int do_cmd2(void *ptr, int argc, char **argv);
static int do_cmd3(void *ptr, int argc, char **argv);
static int do_cmd4(void *ptr, int argc, char **argv);
static int do_quit_system(void *ptr, int argc, char **argv);
static int do_val1(void *ptr, int argc, char **argv);

//二级子函数
static int get_fpga_ch_num(void *ptr, int argc, char **argv);

extern struct cmd_prompt boot_logicapp_root[];
extern struct cmd_prompt boot_fpga_info[];
extern struct cmd_prompt boot_cmd2[];
extern struct cmd_prompt boot_cmd3[];
extern struct cmd_prompt boot_cmd4[];
extern struct cmd_prompt boot_cmd5[];
extern struct cmd_prompt boot_cmd6[];



struct cmd_prompt boot_logicapp_root[] = {
	PROMPT_NODE(boot_fpga_info   ,      do_get_fpga_info,
		 (char*)"op"  ,
		 (char*)"cmd: ch net slot env cyc fpga loss led",
		 (int)  NULL),
	PROMPT_NODE(boot_cmd2   ,      do_cmd2,
		 (char*)"cmd2"  ,
		 (char*)"",
		 (int)  NULL),
	PROMPT_NODE(boot_cmd3   ,      do_cmd3,
		 (char*)"cmd3"  ,
		 (char*)"",
		 (int)  NULL),
	PROMPT_NODE(boot_cmd4   ,      do_cmd4,
		 (char*)"cmd4"  ,
		 (char*)"",
		 (int)  NULL),
	PROMPT_NODE(NULL    ,      do_quit_system,
		 (char*)"quit"  ,
		 (char*)"Exit from current command view",
		 (int)  NULL),
	PROMPT_NODE(NULL    ,      NULL, (char *)NULL, (char *)NULL, (int *) NULL),
};
struct cmd_prompt boot_fpga_info[] = {
	PROMPT_NODE(NULL    ,      get_fpga_ch_num,
		 (char*)"ch"  ,
		 (char*)"get ch num",
		 (int)  CMDP_TYPE_PASS),
	PROMPT_NODE(NULL    ,      NULL, (char *)NULL, (char *)NULL, (int *) NULL),
};
struct cmd_prompt boot_cmd2[] = {
	PROMPT_NODE(NULL    ,      do_val1,
		 (char*)"val2"  ,
		 (char*)"",
		 (int)  CMDP_TYPE_PASS),
	PROMPT_NODE(NULL    ,      NULL, (char *)NULL, (char *)NULL, (int *) NULL),
};
struct cmd_prompt boot_cmd3[] = {
	PROMPT_NODE(NULL    ,      do_val1,
		 (char*)"val3"  ,
		 (char*)"",
		 (int)  CMDP_TYPE_PASS),
	PROMPT_NODE(NULL    ,      NULL, (char *)NULL, (char *)NULL, (int *) NULL),
};
struct cmd_prompt boot_cmd4[] = {
	PROMPT_NODE(NULL    ,      do_val1,
		 (char*)"val3"  ,
		 (char*)"",
		 (int)  CMDP_TYPE_PASS),
	PROMPT_NODE(NULL    ,      NULL, (char *)NULL, (char *)NULL, (int *) NULL),
};
struct cmd_prompt boot_cmd5[] = {
	PROMPT_NODE(NULL    ,      do_val1,
		 (char*)"val3"  ,
		 (char*)"",
		 (int)  CMDP_TYPE_PASS),
	PROMPT_NODE(NULL    ,      NULL, (char *)NULL, (char *)NULL, (int *) NULL),
};
struct cmd_prompt boot_cmd6[] = {
	PROMPT_NODE(NULL    ,      do_val1,
		 (char*)"val3"  ,
		 (char*)"",
		 (int)  CMDP_TYPE_PASS),
	PROMPT_NODE(NULL    ,      NULL, (char *)NULL, (char *)NULL, (int *) NULL),
};


#include "global.h"
#include "hb_app.h"
static int do_get_fpga_info(void *ptr, int argc, char **argv)
{
	
	int32_t  ret,op;
	char *env,cval;
	ret = 0;
	op = 0;
	if(argc >= 2 && strcmp(argv[1], "net") == 0)
	{	
		ret = read_net_flag(0);
		printf("net flag %d \n",ret);
	}
	else if(argc >= 2 && strcmp(argv[1], "slot") == 0)
	{
		ret = read_frame();
		printf("frame %d\n ",ret);
		ret = read_slot();
		printf("slot %d\n ",ret);
	}
	else if(argc >= 2 && strcmp(argv[1], "tsk_id") == 0)
		ret = show_tsk_info();
	
	else if(argc >= 2 && strcmp(argv[1], "fpga") == 0)
	{
		struct fpga_info info;
		memset(&info, 0, sizeof(struct fpga_info));
		anylyze_fpga_Info(&info);
		printf("fpga_info:\ndip switch: 0x%x\nch num 0x%x\nversion 0x%x\n",\
				info.hw_ver, info.ch, info.soft_ver);
	}
	else if(argc >= 2 && strcmp(argv[1], "version") == 0)
	{
		struct fpga_info *pinfo;
		pinfo = &fpga_device_info;
		printf("version:\ndip switch: 0x%x\nch num 0x%x\nversion 0x%x\n",\
				pinfo->hw_ver, pinfo->ch, pinfo->soft_ver);
		if(otdrTestCtrl.mod == OTDR_PARALLE)
			printf("paralle otdr \n");
		else
			printf("serri otdr \n");
	}
	else if(argc >= 3 && strcmp(argv[1], "env") == 0)
	{
		env = getenv(argv[2]);
		printf("name %s env %s \n",argv[2],env);
	}
	else if(argc >= 3 && strcmp(argv[1], "led") == 0)
	{
		op= atoi(argv[2]);
		if(op == 0 || op == 1)
			light_all_led(op);
		else
			printf("%d 输入非法.1 点亮所有告警灯，0 熄灭所有告警灯！\n",op);
	}
	else if(argc >= 3 && strcmp(argv[1], "loss") == 0)
	{
		op= atoi(argv[2]);
		print_fiber_sec_loss(op);
	}
	else if(argc >= 3 && strcmp(argv[1], "cyc") == 0)
	{
		op= atoi(argv[2]);
		if(op == 0 || op == 1){
			otdrTestCtrl.pause_cyc = op;
			printf("pasue_cyc = %d \n",op);
		}
		else
			printf("val %d error, shoud be 0 or 1.\n",op);
	}

	else
		printf("%s\n", __FUNCTION__);
	

		
	return 0;

}

static int do_cmd2(void *ptr, int argc, char **argv)
{
	printf("%s\n", __FUNCTION__);
	return 0;
}

static int do_cmd3(void *ptr, int argc, char **argv)
{
	printf("%s\n", __FUNCTION__);
	return 0;
}

static int do_cmd4(void *ptr, int argc, char **argv)
{
	printf("%s\n", __FUNCTION__);
	return 0;
}

static int do_quit_system(void *ptr, int argc, char **argv)
{
	sh_editpath("");
	sh_up_prompt_level();
	return 0;
}

static int do_val1(void *ptr, int argc, char **argv)
{
	printf("%s\n", __FUNCTION__);
	return 0;
}
static int get_fpga_ch_num(void *ptr, int argc, char **argv)
{
	int32_t  ret, ch;
	ret = 0;
	if(ret == 0)
		printf("%s() %d: ch num %d \n", __FUNCTION__, __LINE__, CH_NUM);
	else
		printf("%s() %d: fail ret  %d \n", __FUNCTION__, __LINE__, ret);
		
	return 0;
}



